package com.tbit.main.pojo.maintain_performance.group;

import com.tbit.main.constant.enums.ConditionLogic;
import com.tbit.main.constant.enums.PerformanceBizType;
import com.tbit.main.constant.enums.PerformanceRuleType;
import com.tbit.main.pojo.PerformanceRule;
import com.tbit.main.pojo.PerformanceRuleGroup;
import com.tbit.main.pojo.maintain_performance.BizRuleGroup;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Collections;

/**
 * 基础绩效
 *
 * @author <a href="mailto:zheng.zebiao@tbit.com.cn">zb</a>
 * @since 2025/2/18
 */
@Data
public class BasicPerformanceGroup implements BizRuleGroup {
    /**
     * 是否启用
     */
    private Boolean enabled;

    /**
     * 有效记录下的绩效
     */
    private BigDecimal validPerformance;

    @Override
    public PerformanceRuleGroup toRaw(PerformanceBizType bizType, Integer accountId) {
        PerformanceRuleGroup group = new PerformanceRuleGroup();
        group.setAccountId(accountId);
        group.setBizType(bizType);
        group.setRuleType(PerformanceRuleType.BASIC);
        group.setEnabled(enabled);

        PerformanceRule rule = new PerformanceRule();
        rule.setPerformance(validPerformance);
        rule.setConditionLogic(ConditionLogic.AND);
        group.setRules(Collections.singletonList(rule));
        return group;
    }

    @Override
    public void initFromRaw(PerformanceRuleGroup group) {
        setEnabled(group.getEnabled());
        for (PerformanceRule rule : group.getRules()) {
            setValidPerformance(rule.getPerformance());
        }
    }
}
